package com.example.ribbontest.command;

import com.example.ribbontest.domain.User;
import com.example.ribbontest.service.UserService;
import com.netflix.hystrix.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static com.netflix.hystrix.HystrixCommandGroupKey.Factory.asKey;

public class UserBatchCommand extends HystrixCommand<List<User>> {

    @Autowired
    UserService userService;
    List<Integer> userIds;

    protected UserBatchCommand(UserService userService,List<Integer> userIds) {
        super(Setter.withGroupKey(asKey("userServiceCommand")));
        this.userIds = userIds;
        this.userService = userService;
    }

    @Override
    protected List<User> run() throws Exception {
        return userService.getUsers(userIds);
    }
}
